﻿using System;
using Medianamik.Core;
using Medianamik.Core.DAL.Repositories;
using Medianamik.Core.Sugar;
using Medianamik.UI.Web.MVP.Presentation;

namespace Medianamik.UI.Web.Shop.Presentation.Presenters
{
    public class AttributeTypeValueListPresenter<TView>
        : ModulePresenterWithGrid<Node, TView, IMedianamikRepository<Node>, INodeTypeRepository, IMedianamikRepository<IMedianamikDTOWithName>>
        where TView : class, IAttributeValueListView
    {
        public AttributeTypeValueListPresenter(TView view, IMedianamikRepository<Node> repository, INodeTypeRepository nodeTypeRepository, IMedianamikRepository<IMedianamikDTOWithName> baseTypeRepository)
            : base(view, repository, nodeTypeRepository, baseTypeRepository)
        {
        }

        protected override string BuildReturnUrl()
        {
            return base.BuildReturnUrl().AddParam(DefaultParamNames.TypeID, BaseTypeId);
        }

        protected override void Initialize(object sender, EventArgs e)
        {
            base.Initialize(sender, e);

            if (BaseTypeId == Guid.Empty)
                View.Redirect(Pages.AttributeTypeList);
        }

        protected override string SetNameColumn(Node element)
        {
            return (string)element.DefaultInstance.Properties[Constants.DefaultAttributeTypeValuePropertyName].Value;
        }
    }
}
